<template>
  <el-container class="home_container">
    <el-header class="top_header">
      <el-row :gutter="20">
        <el-col :span="4" class="left_col"
          ><img
            class="logo"
            src="https://img1.baidu.com/it/u=1792249350,650626052&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1677776400&t=1206029bd5ed406defb4a36031b96ca8"
            alt=""
        /></el-col>
        <el-col :span="16" class="center_col">后台管理系统</el-col>
        <el-col class="right_col" :span="4">
          <el-dropdown trigger="click">
            <span class="el-dropdown-link">
              更多选项
              <el-icon class="el-icon--right">
                <arrow-down />
              </el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>退出登陆</el-dropdown-item>
                <el-dropdown-item @click="toggleDark()"
                  >一键换肤</el-dropdown-item
                >
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="200px" class="aside">
        <el-menu default-active="1" class="el-menu-vertical">
          <el-sub-menu index="2">
            <template #title>
              <el-icon><location /></el-icon>
              <span>首页</span>
            </template>
            <el-menu-item-group
              v-for="item in filterHasChildren[0].children"
              :key="item.path"
            >
              <el-menu-item :key="item.path" @click="handleOpen(item.path)">
                <el-icon><icon-menu /></el-icon>
              {{
                item.meta.title
              }}</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
          <el-menu-item
            index="2"
            v-for="item in filterNoChildren"
            :key="item.path"
            @click="handleOpen(item.path)"
          >
            <el-icon><icon-menu /></el-icon>
            <span v-if="item.meta">{{ item.meta.title }}</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script lang="ts" setup>
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'
import { ArrowDown } from "@element-plus/icons-vue";
import { toggleDark } from "../../composables";
import { RouteRecordRaw, useRouter } from "vue-router";
import { reactive, computed } from "vue";
import { displayNoneMenuArr } from "~/config/config-ignore";

const router = useRouter();
let menuList = reactive<RouteRecordRaw[]>([]) as any;

// filter menu list
const showMenuList = router.options.routes.filter(v => !displayNoneMenuArr.includes(v.path));
menuList.value = showMenuList;
const filterNoChildren = computed(() =>menuList.value.filter((ite: any) => !ite.children));
const filterHasChildren = computed(() =>
  menuList.value.filter((ite: any) => ite.children)
);

// click menu item
const handleOpen = (key: string) => {
  router.push(key);
};

</script>

<style scoped lang="scss">
.home_container {
  width: 100%;
  height: 100%;
  .top_header {
    width: 100%;
    height: 50px;
    background: var(--ep-bg-color-page);

    .logo {
      border-radius: 5px;
      width: 50px;
      height: 50px;
    }
    .right_col,
    .left_col,
    .center_col {
      display: flex;
      align-items: center;
      justify-content: space-around;
    }
  }
  .aside {
    height: 100%;
    .el-menu-vertical {
      height: 100%;
    }
  }
}
</style>
